package io.github.kouleen.minecraft.plugin.redpacket.listener;

import io.github.kouleen.minecraft.core.lang.annotation.MinecraftPluginListener;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;

/**
 * @author zhangqing
 * @since 2025/10/6 18:47
 */
@MinecraftPluginListener
public class InventoryClickListener implements Listener {

    /**
     * 处理Inventory点击事件，防止玩家拿取奖励界面中的物品
     */
    @EventHandler
    public void onInventoryClick(InventoryClickEvent event) {
        // 检查是否是红包领取成功界面
        if (event.getView().getTitle().equals("§e§l红包领取成功!")) {
            // 取消点击事件，防止玩家拿取物品
            event.setCancelled(true);
            // 如果是玩家试图拿取物品，则发送提示消息
            if (event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR) {
                Player player = (Player) event.getWhoClicked();
                player.sendMessage("§c这是展示界面，无法拿取物品!");
            }
        }
    }
}
